import { defineStore } from "pinia";
import { reactive } from "vue";

interface IBreadcrumb {
  path?: string;
  title: string;
}

export const useBreadcrumbStore = defineStore("breadcrumb", () => {
  const breadcrumbs = reactive<IBreadcrumb[]>([
    {
      path: "/Admin/Home",
      title: "首页",
    },
  ]);

  function changeBreadcrumb(path: string, titles:string[]) {
    
    breadcrumbs.splice(1);

    if (titles.length==0) {
      return;
    }

      titles.forEach(item=>{
        breadcrumbs.push({
          path: path,
          title: item,
        })
      })

      breadcrumbs[breadcrumbs.length-1].path = path;

  }

  return {
    breadcrumbs,
    changeBreadcrumb,
  };
});
